<?php
	defined('BASEPATH') or die('forbidden');
	class rolelogin_Controller Extends Controller
	{
		private $rolename;
		private $platformList;	//平台列表
		private $professionList;	//职业列表
		private $logdb;	//数据库连接
		private $joblist;	//职务列表
		private $nameConn;
		private $nameList;
		
		function _init()
		{	//echo $_SESSION['rolelogin'];
			check_level(50,segment(0),segment(1),segment(2,'index'));
			set_time_limit(0);
		$this->inc = $this->config['inc'];
		$this->platformList = $this->inc['platform_list'];
		$this->professionList = $this->inc['type_proffessionid'];
		$this->joblist = array('-1'=>'无公会','0'=>'会长','1'=>'副会长','2'=>'精英','3'=>'普通会员', '4'=>'职务数量');
		//得到选择的区号
		$areanum = $_SESSION['area_selected_id'];
        if ($areanum == '') 
        {
            echo "<script>alert('" . translate('C_SELECT_AREA_TEXT') . "');</script>";
            return;
        }
        $this->nameConn = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_GAMESERVER);
        $this->nameConn->query("SELECT id, name FROM player");
        while ($n = $this->nameConn->get_array('default'))
        {
        	$this->nameList[$n['id']] = $n['name'];
        }
        $this->nameConn->free_all();
        // log数据库
		$this->logdb = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_LOG);
		
		if (false == $this->logdb) {
			//内部有提示错误，在此就不提示了
			 //echo "<script>alert(' connect areanum:$areanum error ');</script>";
            return;
		}	
		
	}
		
		function index()
		{	
			$this->view->display("logrole/rolelogin/index");
		}
		function flexigrid() 
		{
			list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();
			$sql = "SELECT COUNT(*) AS num FROM rolelogin ";
			//$sql = "SELECT COUNT(*) AS num FROM $row[logname].accountlogin  where {$where} ";
			//echo " sql2:$sql ";
			$one = $this->logdb->one($sql);
			$total = $one['num'];
			$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";
				
			$sql = "SELECT {$colsinfo} FROM rolelogin  where {$where}  {$orderby} LIMIT {$offset},{$rp}";
			//$sql = "SELECT {$colsinfo} FROM $row[logname].accountlogin  where {$where}  {$orderby} LIMIT {$offset},{$rp}";
			//echo "sql2 = $sql";
			$this->logdb->query($sql);
			//$id = 0;
			while ($n = $this->logdb->get_array('default'))
			{
				$n['platform_id']=$this->platformList[$n['platform_id']]."(".$n['platform_id'].")";
				$n['profession_type']=$this->professionList[$n['profession_type']]."(".$n['profession_type'].")";
				$n['pre_role_position']=$this->joblist[$n['pre_role_position']]."-(".$n['pre_role_position'].")";
				$n['role_id']=$this->nameList[$n['role_id']]."(".$n['role_id'].")";
				$rows[] = array('id' => $n['id'], 'cell' => $n);
				//$id = $id+1;
			}
			//var_dump($rows);
			$result = array(
		            'page' => $page,
		            'total' => $total,
		            'rows' => $rows
			);
				
			//$this->logdb->free_all();
			echo json_encode($result);
		}
	}
?>